package org.study.event.core.eventbus.support;

import org.springframework.beans.factory.FactoryBean;
import org.springframework.beans.factory.InitializingBean;
import org.study.event.core.eventbus.EventBusManager;

/**
 * 
 * 生产 EventBus的工厂Bean
 * 
 * <p>
 * 当然 也可以不使用这个bean工厂 ,自己配置呢,EventBusManager 配置的时候可以指定初始化方法,如
 * <p>
 * <b>&lt;bean id="eventBusManager"
 * <font color='red'>init-method="intEventBusManager"</font>&gt;<br/>
 * &nbsp;&nbsp;&nbsp;&lt;property name="***" value="***" /&gt; <br>
 * &lt;/bean&gt; </b>
 * <p>
 * </p>
 * 
 * @author 陈波
 *
 */
public class EventBusManagerFactoryBean implements FactoryBean<EventBusManager>, InitializingBean {

	private EventBusManager target;

	@Override
	public EventBusManager getObject() throws Exception {
		if (target == null) {
			afterPropertiesSet();
		}
		return target;
	}

	@Override
	public Class<?> getObjectType() {
		return target.getClass();
	}

	@Override
	public boolean isSingleton() {
		return true;
	}

	@Override
	public void afterPropertiesSet() throws Exception {
		if (target != null) {
			target.intEventBusManager();
		}
	}

}
